<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app" style="border: 1px solid green; padding:15px">
        <div>这里是父组件的区域 --> {{parentMsg}}</div>
        <children @on-push='getPush'></children>
    </div>
    <script>
        Vue.component('children',{
                template:`
                    <div style="border:1px solid red">{{msg}}
                        <button @click="pushParent">向父组件给东西</button>
                        </div>
                `,
                data(){
                    return{
                        msg:"子组件的内容"
                    }
                },
                methods:{
                    pushParent(){
                        this.$emit('on-push',this.msg)
                    }
                }
        })

        new Vue({
            el:"#app",
            data:{
                    parentMsg:""
            },
            methods:{
                getPush(val){
                    this.parentMsg = val
                }
            }
        })
    </script>
</body>
</html>